package com.hubujun.driverlicense.network.api;

import android.content.Context;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.hubujun.driverlicense.DLCore;

import org.json.JSONObject;

/**
 * Created by Administrator on 2016/5/29 0029.
 */
public class QuestionAPI extends BaseAPI {
    private static QuestionAPI sInstance;

    /**
     * 单例
     *
     * @return instance
     */
    public final static synchronized QuestionAPI instance() {
        if (sInstance == null) {
            sInstance = new QuestionAPI();
        }

        return sInstance;
    }

    private QuestionAPI() {
    }

    @Override
    public String getApiUrl() {
        return "http://api2.juheapi.com/jztk/query";
    }

    public void requestQuestions(final Context context, final Response.Listener<JSONObject> listener, final Response.ErrorListener errorListener) {
        DLCore.getHandleThread().post(new Runnable() {
            @Override
            public void run() {
                RequestQueue mQueue = Volley.newRequestQueue(context);
                JsonObjectRequest stringRequest = new JsonObjectRequest(getApiUrl() + "?subject=1&model=c1&testType=rand&=&key=9fccfbaf3eb0a40379c4a35df28314b2", listener, errorListener);
                mQueue.add(stringRequest);
            }
        });
    }
}
